<?php
header("content-type:text/html;charset=utf-8");
//链接数据库并选择数据库
$link = mysqli_connect("149.129.94.81","student","student","student");
//执行sql语句
$x =[];
$da =[];
if($link){
	$result = mysqli_query($link,"select * from evaluation");
	if($result){
		$data = mysqli_fetch_all($result,1);
		foreach($data as $value){
			$x[] = $value['type'];
			$da[] = $value['grade'];
		}
	}
}

//处理结果集
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="dist/echarts.js"></script>
	</head>
	<body>
		<div id="main" style="height:600px;width:500px;"></div>
		<script>
			var dom=document.getElementById('main')
			var myChart = echarts.init(dom,'dark');
			// 绘制图表
			myChart.setOption({
			  title: {
			    text: 'ECharts 入门示例'
			  },
			  tooltip: {},
			  xAxis: {
			    data: <?php echo json_encode($x) ?>
			  },
			  yAxis: {},
			  series: [
			    {
					color:[
						 '#dd6b66',
						 '#759aa0',
						 '#e69d87',
						 '#8dc1a9',
						 '#ea7e53',
					],
			      name: '销量',
			      type: 'pie',//bar
			      data: <?php echo json_encode($da) ?>
			    }		
			  ]
				});
		</script>
	</body>
</html>